#ifndef ACAPELLA_THREAD_WINDOWS_THREAD_HPP
#define ACAPELLA_THREAD_WINDOWS_THREAD_HPP

#include "windows.h"
#include "thread_traits.h"

namespace acapella
{
namespace thread
{

class Thread_Windows
{
public:
	typedef _thread_traits<acapella_os_windows>::ThreadHandle ThreadHandle;
	typedef _thread_traits<acapella_os_windows>::ThreadParam ThreadParam;
	typedef _thread_traits<acapella_os_windows>::ThreadFunc ThreadFunc;

	static ThreadHandle Current()
	{
		return ::GetCurrentThread();
	}

	static int Cleanup(ThreadHandle handle)
	{
		::CloseHandle(handle);

		return 0;
	}

	static int Create(ThreadHandle* pHandle, _uint32_ stackSize, ThreadFunc func, ThreadParam param)
	{
		DWORD threadID;
		*pHandle = ::CreateThread(NULL, 0, func, param, 0, &threadID);
		if (*pHandle == NULL)
		{
			return -1;
		}
		return 0;
	}

	static int Exit(_uint32_ retcode)
	{
		::ExitThread(retcode);

		return 0;
	}

	static int Join(ThreadHandle handle, void ** rval_ptr)
	{
		return ::WaitForSingleObject((HANDLE)handle,0);
	}


};


}
}



#endif
